package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"
	"house/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type ResDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewResDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResDelLogic {
	return &ResDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ResDelLogic) ResDel(in *houserpc.ResDelRequest) (*houserpc.ResDelResponse, error) {
	// todo: add your logic here and delete this line

	begin := mysql.DB.Debug().Begin()
	var res = mysql.Res{
		Model:  gorm.Model{ID: uint(in.ResId)},
		Statue: "已取消",
	}
	err := begin.Updates(&res).Error

	if err != nil {
		return nil, fmt.Errorf("取消失败")
		begin.Rollback()
	}

	begin.Commit()

	return &houserpc.ResDelResponse{
		ResId: int64(res.ID),
	}, nil
}
